package com.konne.nightmare.FastPublicOpinion.mvp.presenter;

import android.os.Handler;

import com.blankj.utilcode.util.ActivityUtils;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.bean.MembersBean;
import com.konne.nightmare.FastPublicOpinion.bean.StudentTeamBean;
import com.konne.nightmare.FastPublicOpinion.mvp.view.IMainView;
import com.konne.nightmare.FastPublicOpinion.mvp.view.IMembersManagerView;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.AddTeacherDialog;
import com.konne.nightmare.FastPublicOpinion.ui.information.adapter.MembersManagerMAdapter;
import com.konne.nightmare.FastPublicOpinion.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class MembersManagerPresenter extends BaseMvpPresenter<IMembersManagerView> {
    private List<MembersBean> teachers;
    private List<MembersBean> students;
    private List<MembersBean> datas;
    public void init(){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                getData();
            }
        },500);

    }
    public void action(int action) {
        switch (action){
            case 1://团队关
                datas.get(0).setOpen(false);
                List<MembersBean> items=new ArrayList<>();
                items.add(datas.get(0));
                items.add(datas.get(teachers.size()+1));

                if(items.get(1).isOpen()){
                    items.addAll(students);
                }
                getView().updataMembers(items,datas.size()-2);

                break;
            case 2://团队开
                datas.get(0).setOpen(true);
                List<MembersBean> itemOpen=new ArrayList<>();
                itemOpen.add(datas.get(0));
                itemOpen.addAll(teachers);
                MembersBean teamOpen=datas.get(teachers.size()+1);
                itemOpen.add(teamOpen);
                if(teamOpen.isOpen()){
                    itemOpen.addAll(students);
                }
                getView().updataMembers(itemOpen,datas.size()-2);

                break;
            case 3://学生关
                List<MembersBean> sitem=new ArrayList<>();
                sitem.add(datas.get(0));
                if(sitem.get(0).isOpen()){
                    sitem.addAll(teachers);
                }
                MembersBean sT=datas.get(teachers.size()+1);
                sT.setOpen(false);
                sitem.add(sT);

                getView().updataMembers(sitem,datas.size()-2);
                break;
            case 4://学生开
                List<MembersBean> sitemOpen=new ArrayList<>();
                sitemOpen.add(datas.get(0));
                if(sitemOpen.get(0).isOpen()){
                    sitemOpen.addAll(teachers);
                }
                MembersBean sTOpen=datas.get(teachers.size()+1);
                sTOpen.setOpen(true);
                sitemOpen.add(sTOpen);
                sitemOpen.addAll(students);
                getView().updataMembers(sitemOpen,datas.size()-2);
                break;
            case 5://添加助教
                new AddTeacherDialog(ActivityUtils.getTopActivity()).setAddTeacherListener(new AddTeacherDialog.AddTeacherListener() {
                    @Override
                    public void addTeacher(String id) {
                        ToastUtil.showSuccessToast("添加老师/助教成功");
                    }
                }).show();
                break;
        }
    }
    private void getData(){
         datas=new ArrayList<>();

        teachers=testGetTeachers();
        for (int i = 0; i < teachers.size(); i++) {
            teachers.get(i).setType(MembersManagerMAdapter.MenberType.Teacher.type);
        }
        students  =testGetStudents();
        for (int i = 0; i < teachers.size(); i++) {
            students.get(i).setType(MembersManagerMAdapter.MenberType.Student.type);
        }
        MembersBean tGroup=new MembersBean();
        tGroup.setType(MembersManagerMAdapter.MenberType.TeacherGroup.type);
        datas.add(tGroup);
        datas.addAll(teachers);
        MembersBean sGroup=new MembersBean();
        sGroup.setType(MembersManagerMAdapter.MenberType.StudentGroup.type);
        datas.add(sGroup);
        datas.addAll(students);

        getView().updataMembers(datas,datas.size()-2);
        List<StudentTeamBean> studentTeams=testGetSTeams();
        getView().updataStudentTeams(studentTeams,testGetSTeams().size());
    }

    private List<StudentTeamBean> testGetSTeams(){
        List<StudentTeamBean> teams=new ArrayList<>();
        StudentTeamBean bean=new StudentTeamBean();
        bean.setType(0);
        bean.setGroupNum(1);
        bean.setTitle("11月30日课下分组");
        bean.setIntoUserNum(9);
        bean.setUnIntoUserNum(9);
        teams.add(bean);
        bean=new StudentTeamBean();
        bean.setType(1);
        bean.setGroupNum(1);
        bean.setTitle("11月30日课下分组");
        bean.setIntoUserNum(9);
        bean.setUnIntoUserNum(9);
        teams.add(bean);
        bean=new StudentTeamBean();
        bean.setType(2);
        bean.setGroupNum(1);
        bean.setTitle("11月30日课下分组");
        bean.setIntoUserNum(10);
        bean.setUnIntoUserNum(9);
        teams.add(bean);
        bean=new StudentTeamBean();
        bean.setType(3);
        bean.setGroupNum(1);
        bean.setTitle("11月30日课下分组");
        bean.setIntoUserNum(9);
        bean.setUnIntoUserNum(9);
        teams.add(bean);
        bean=new StudentTeamBean();
        bean.setType(0);
        bean.setGroupNum(1);
        bean.setTitle("11月30日课下分组");
        bean.setIntoUserNum(3);
        bean.setUnIntoUserNum(9);
        teams.add(bean);
        return teams;
    }
    private List<MembersBean>  testGetTeachers(){
        List<MembersBean> teachers=new ArrayList<>();
        MembersBean bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fc2%2F88%2F07%2Fc2880735e9b777937f8453e4bf1d91f9.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=507a996076e1dbcf963ecf1302d650a0");
        bean.setName("老师1");
        bean.setRole("老师");
        teachers.add(bean);
         bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2Ff5%2Fd8%2F3e%2Ff5d83ebf93ff8da4badbe62ade1605e5.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=fa52948f2195a01683fe20c428797a93");
        bean.setName("老师2");
        bean.setRole("助教");
        teachers.add(bean);
        return teachers;
    }
    private List<MembersBean>  testGetStudents(){
        List<MembersBean> teachers=new ArrayList<>();
        MembersBean bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fa7%2F57%2F85%2Fa757850a29db44013a12ae694c12490f.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=16a15a471d03f722fb59921f8d847d1a");
        bean.setName("学生1");
        teachers.add(bean);
        bean=new MembersBean();
        bean.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.bq233.com%2Fkanqq%2Fpic%2Fupload%2F2018%2F0723%2F1532329172809328.jpg&refer=http%3A%2F%2Fimg.bq233.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1645609764&t=1f5daa4d0a127ba306e5b5c1a4228729");
        bean.setName("学生2");
        teachers.add(bean);
        return teachers;
    }
}
